import { Injectable } from '@angular/core';
import { Crisis, CRISES } from './mock-crisis';

let crisisPromise = Promise.resolve(CRISES);

@Injectable()
export class CrisisService {
  selectCrisis: Crisis;
  getcrisis() { return crisisPromise; }

  getCrisis(id: number | string) {
    return crisisPromise
      // (+) before `id` turns the string into a number
      .then(crisis => CRISES.find(item => item.id === +id));
  }
}
